
interface TreeNode {
  id: number;
  pid?: number;
  level: number;
  name: string;
}
class MiddleFunction{
// 获取统一分支下的所有节点集合
static getSameBranch(tree: TreeNode[], targetName: string): string[]{
  const names: string[] = [];
  for (const node of tree) {
      if (node.name === targetName) {
          // 找到目标节点后，递归查找子节点的name
          const descendantNames = this.findDescendants(tree, node.id);
          names.push(node.name, ...descendantNames);
      }
  }
  return names;
 }
 
 static findDescendants(tree: TreeNode[], parentId: number): string[] {
  const names: string[] = [];
  for (const node of tree) {
      if (node.pid === parentId) {
          names.push(node.name);
          // 递归查找子节点的name
          const descendantNames = this.findDescendants(tree, node.id);
          names.push(...descendantNames);
      }
  }
  return names;
}
}
export default MiddleFunction